
#include "UIDisplayObjects.h"
#include <SDL2/SDL_opengl.h>

#include <ALittleClient/LogSystem/LogSystem.h>

namespace ALittle
{

UIDisplayObjects::UIDisplayObjects()
: m_visible(true), m_x(0), m_y(0), m_angle(0)
{ }

UIDisplayObjects::~UIDisplayObjects()
{ }

void UIDisplayObjects::SetVisible(bool visible)
{
	m_visible = visible;
}

void UIDisplayObjects::SetX(float x)
{
	m_x = x;
}

void UIDisplayObjects::SetY(float y)
{
	m_y = y;
}

void UIDisplayObjects::SetAngle(float angle)
{
	m_angle = angle;
}

void UIDisplayObjects::Render()
{
	if (!m_visible) return;
	if (m_display_list.size() == 0) return;

	glPushMatrix();
	glTranslatef(m_x, m_y, 0);
	if (m_angle != 0.0f) glRotatef(m_angle, 0.0f, 0.0f, 1.0f);
	DisplayList::iterator it, end = m_display_list.end();
	for (it = m_display_list.begin(); it != end; ++it)
		(*it)->Render();
	glPopMatrix();
}

void UIDisplayObjects::AddChild(UIDisplayObject* object)
{
	if (object == NULL)
	{
		ALITTLE_ERROR("object is null!");
		return;
	}
	m_display_list.push_back(object);
}

void UIDisplayObjects::RemoveChild(UIDisplayObject* object)
{
	if (object == NULL)
	{
		ALITTLE_ERROR("object is null!");
		return;
	}

	m_display_list.remove(object);
}

void UIDisplayObjects::RemoveAll()
{
	m_display_list.resize(0);
}

} // ALittle
